package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.CarInformation;
import cn.wolfcode.crm.mapper.CarInformationMapper;
import cn.wolfcode.crm.query.impl.CarInformationQuery;
import cn.wolfcode.crm.service.ICarInformationService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CarInformationServiceImpl implements ICarInformationService {
    @Autowired
    CarInformationMapper carInformationMapper;

    public void delete(Long id) {
        carInformationMapper.deleteByPrimaryKey(id);
    }

    public void saveOrUpdate(CarInformation record) {
        if (record.getId() != null) {
            carInformationMapper.updateByPrimaryKey(record);
        } else {
            carInformationMapper.insert(record);
        }
    }

    public CarInformation get(Long id) {
        return carInformationMapper.selectByPrimaryKey(id);
    }

    public List<CarInformation> getAll() {
        return carInformationMapper.selectAll();
    }


    public PageResult query(CarInformationQuery qo) {
        int rows = carInformationMapper.queryForCount(qo);
        if (rows == 0) {
            new PageResult(rows, Collections.EMPTY_LIST);
        }
        List<CarInformation> result = carInformationMapper.queryForList(qo);
        return new PageResult(rows, result);
    }

    @Override
    public void insert(CarInformation car) {
        carInformationMapper.insert(car);
    }

    @Override
    public CarInformation getCar(String name, String carnumber) {
        return carInformationMapper.getCar(name,carnumber);
    }
}
